package com.fpc.cn.springbootutil.user;

import com.alibaba.fastjson.JSON;
import com.fpc.cn.springbootutil.annotation.paramTrim.TrimRequestParams;
import com.fpc.cn.springbootutil.base.BaseResponse;
import com.fpc.cn.springbootutil.base.BaseUtilService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);
    @Autowired
    private UserService userService;


    @Autowired
    private BaseUtilService baseUtilService;


    /**
     *   @TrimRequestParams 注解测试
     * @param map
     */
    @PostMapping("/test")
    public String test(@RequestBody Map<String,Object> map) {
        logger.info("111112222");
        log.info("=======>>>>>333333333<<<<<========");
        return "处理后的参数: " ;
    }
    /**
     * @TrimRequestParams 注解测试
     * @param
     */
    @PostMapping("/test1")
    @TrimRequestParams(notNullCheck=true,lengthCheck=true)
    public String test(@RequestBody User user) {
        System.out.println(  user.getUserName());
        return "处理后的参数: " +JSON.toJSONString(user);
    }

    /**
     *    数据库连接测试
     * @param
     */
    @PostMapping("/selectList")
    public String selectList(@RequestBody User user) {
        List<Map<String,Object>> dsa= userService.selectList(user);
        for (int i = 0; i < dsa.size(); i++) {
            System.out.println(dsa.get(i));
        }
        return "处理后的参数: " + user.getUserName() ;
    }

    /**
     * @date 2025/4/28
     * @describe
     */
    @PostMapping(value="/createUser")
    public BaseResponse createUser(@RequestBody User user) {


        return userService.createUser(user);
    }

    /**
     * @date 2025/4/28
     * @describe
     */
    @PostMapping(value="/bathCreateUser")
    public BaseResponse bathCreateUser(@RequestBody User user) {

        return  userService.bathCreateUser(user);
    }


}
